﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace Timesheet
{
    public partial class Test51CTO : Form
    {
        public Test51CTO()
        {
            InitializeComponent();
        }

        private void btnLogIn_Click(object sender, EventArgs e)
        {
            if (!checkRequiredFields())
            {
                return;
            }

            string strUser = this.tbUserName.Text.Trim();
            string strPwd = this.tbPassword.Text.Trim();

            HttpWebResponse httpResponse = Test51CTOSystem.logIn(strUser, strPwd);
            String strResponse = WebUtility.getHtmlStringFromWebResponse(httpResponse);
            GeneralUtility.writeStringToFile(strResponse, GeneralUtility.TEST_FILE_1);

            if (strResponse.Contains("账号或密码错误"))
            {
                MessageBox.Show("Log in Failed!");
            }
            else
            {
                MessageBox.Show("Log in Succeed!");
            }

        }

        /// <summary>
        /// Check requried fields
        /// </summary>
        /// <returns></returns>
        private bool checkRequiredFields()
        {
            if (string.IsNullOrEmpty(this.tbUserName.Text.Trim()))
            {
                MessageBox.Show("Please enter user name!");
                return false;
            }

            if (string.IsNullOrEmpty(this.tbPassword.Text.Trim()))
            {
                MessageBox.Show("Please enter password!");
                return false;
            }

            return true;
        }
    }
}
